package com.pureut.system.controller;

import java.util.Arrays;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.InventoryPlan;
import com.pureut.system.domain.vo.InventoryPlanVo;
import com.pureut.system.service.IInventoryPlanService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-08 14:06:35
 * @Desc: 库存盘点方案表Controller
 */
@RestController
@RequestMapping("/system/inventoryPlan")
public class InventoryPlanController extends BaseController {

    /**
     * 库存盘点方案表Service
     */
    @Resource
    private IInventoryPlanService inventoryPlanService;

    /**
     * 查询库存盘点方案表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("inventoryPlan-list")
    @GetMapping("/list")
    public TableDataInfo list( InventoryPlanVo inventoryPlanVo) {
        startPage();
        LambdaQueryWrapper<InventoryPlan> resultQuery = new LambdaQueryWrapper<InventoryPlan>();
        if(ObjectUtil.isNotNull(inventoryPlanVo.getPlanCode())){
            resultQuery.like(InventoryPlan::getPlanCode, inventoryPlanVo.getPlanCode());
        }
        if(ObjectUtil.isNotNull(inventoryPlanVo.getInventoryObject())){
            resultQuery.like(InventoryPlan::getInventoryObject, inventoryPlanVo.getInventoryObject());
        }
        if(ObjectUtil.isNotNull(inventoryPlanVo.getInventoryObject())){
            resultQuery.like(InventoryPlan::getInventoryObject, inventoryPlanVo.getInventoryObject());
        }
        if(ObjectUtil.isNotNull(inventoryPlanVo.getInventoryBatch())){
            resultQuery.like(InventoryPlan::getInventoryBatch, inventoryPlanVo.getInventoryBatch());
        }
        if(ObjectUtil.isNotNull(inventoryPlanVo.getNextInventoryDate())){
            resultQuery.eq(InventoryPlan::getNextInventoryDate, inventoryPlanVo.getNextInventoryDate());
        }

        return getDataTable(inventoryPlanService.list(resultQuery));
    }


    /**
     * 获取库存盘点方案表详细信息
     * @param: id 库存盘点方案表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("inventoryPlan-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(inventoryPlanService.getById(id));
    }

    /**
     * 新增库存盘点方案表
     * @param: inventoryPlan 库存盘点方案表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("inventoryPlan-add")
    @PostMapping
    public AjaxResult add(@RequestBody InventoryPlanVo inventoryPlanVo) {
        return toAjax(inventoryPlanService.save(inventoryPlanVo));
    }

    /**
     * 修改库存盘点方案表
     * @param: inventoryPlan 库存盘点方案表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("inventoryPlan-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody InventoryPlanVo inventoryPlanVo) {
        return toAjax(inventoryPlanService.updateById(inventoryPlanVo));
    }

    /**
     * 删除库存盘点方案表
     * @param: id 库存盘点方案表主键
     * @return: Json工具类对象
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inventoryPlanService.removeByIds(Arrays.asList(ids)));
    }
}
